#include "pcapsendqueue.h"
#include "packetcapapi.h"

CPCapSendQueue::CPCapSendQueue(QObject *parent) :
    QObject(parent)
{
    qDebug("[CPCapSendQueue]constructed");
    pcap_send_queue *pcap_queue = wpcap_api_arg1(pcap_sendqueue_alloc, 655360);
    m_queue = pcap_queue;
}

CPCapSendQueue::~CPCapSendQueue()
{
    qDebug("[CPCapSendQueue]destroyed");
    pcap_send_queue *pcap_queue = reinterpret_cast<pcap_send_queue*>(m_queue);
    wpcap_api_arg1(pcap_sendqueue_destroy, pcap_queue);
}

int CPCapSendQueue::append(CPCapPktData *data)
{
    pcap_pkthdr pcap_header;
    pcap_header.caplen = 0;
    pcap_header.len = 0;

    pcap_send_queue *pcap_queue = reinterpret_cast<pcap_send_queue*>(m_queue);
    u_int len = pcap_queue->len;
    wpcap_api_arg3(pcap_sendqueue_queue, pcap_queue, &pcap_header, (const u_char*)data->data().data());
    return pcap_queue->len - len;
}

int CPCapSendQueue::transmit(CPCapHandle *handle)
{
    //pcap_t *pcap_handle = reinterpret_cast<pcap_t*>(handle->handle());
    //pcap_send_queue *pcap_queue = reinterpret_cast<pcap_send_queue*>(m_queue);
    //int result = wpcap_api_arg3(pcap_sendqueue_transmit, pcap_handle, pcap_queue, 0);
    //return result;
    return 0;
}
